package com.qianyu.project.service.smj;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qianyu.project.core.annotation.FlowBegin;
import com.qianyu.project.core.annotation.FlowEntry;
import com.qianyu.project.entity.Fragmentary;
import com.qianyu.project.mapper.provider.smj.smjFragmentaryDao;
import com.qianyu.project.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;

@Service
public class smjFragmentaryServiceImpl implements smjFragmentaryService {
    @Autowired
    private smjFragmentaryDao fd;

    @Override//连接零星劳务单
    public String AddFragmentary(String apply_date, String p_id, String type, String handler_id, String comment, String attach_ids) {
        String update_date = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        String[] ids = update_date.split(" ");
        String ids1 =ids[0];
        String ids2 =ids[1];
        String[] ids3 = ids1.split("-");
        String[] ids4 = ids2.split(":");
        String id ="";
        for (int i = 0; i <ids3.length ; i++) {
            id += ids3[i];
        }
        for (int i = 0; i <ids4.length ; i++) {
            id += ids4[i];
        }
        fd.AddFragmentary( id, apply_date, p_id, type, handler_id, comment, attach_ids);
        return id;
    }

    @Override//添加工程量清单
    public void AddWorkList(String fragmentary_id, String work_content, String unit, String unit_price, String number) {
        String sumnumber = Integer.valueOf(unit_price)*Integer.valueOf(number)+"";
        fd.AddWorkList( fragmentary_id, work_content, unit, unit_price, number,sumnumber);
    }

    @FlowBegin("fragmentary")//发起审批
    @Override
    public Integer FlowFragmentary(@FlowEntry("id") Fragmentary fragmentary) {
        fd.UpdateApproveStatus(1, fragmentary.getId());
        return 1;
    }

    @Override//查看零星劳务列表
    public IPage<Map<String, Object>> ListFragmentary(Map<String, String> params) {
        IPage<Map<String, Object>> page= PageUtil.createPage(params);
        return fd.ListFragmentary(page, params);
    }

    @Override//获取工程量清单
    public List<Map<String, Object>> getWorkList(String fragmentary_id) {
        return fd.getWorkList(fragmentary_id);
    }

    @Override
    public List<Map<String, Object>> getfromaudit(String id) {
        String fid = fd.getFid(id);
        return fd.getfromaudit(fid);
    }
}
